home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10940 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: BoundsChecker and fgets fmalloc problems
  5. Date: Wed, 20 Mar 96 21:26:36 GMT
  6. Organization: none
  7. Message-ID: <827357196snz@genesis.demon.co.uk>
  8. References: <4ikfds$h8c@nnrp1.news.primenet.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ikfds$h8c@nnrp1.news.primenet.com>
  15.            bri@primenet.com "Brian Gregory" writes:
  16.  
  17. >I am using Bounds Checker v2.5, and am having a problem finding a
  18. >memory leak it is reporting...
  19. >
  20. >Example:
  21. >
  22. >fgets( szBuf, 799, fpIn );
  23. >
  24. >szBuf is an 800 character buffer (pre-sized array)
  25.  
  26. In that case write:
  27.  
  28.     fgets( szBuf, 800, fpIn );
  29.  
  30. or better still, since explicit constannts like this are a maintenance
  31. nightmare:
  32.  
  33.     fgets( szBuf, sizeof szBuf, fpIn );
  34.  
  35. Or #define a buffer size.
  36.  
  37. Make sure you test the return code of fgets().
  38.  
  39. >fpIn IS a valid pointer
  40.  
  41. I'll have to take your word for it. However a minimal working example
  42. which showed the problem would be proof.
  43.  
  44. >no memory is corrupt before the fgets line
  45.  
  46. You'll need to convince me a lot harder than that.
  47.  
  48. >The application is a windows app, written in straight C with a large
  49. >memory model.
  50.  
  51. If those are relevant to your problem you should be posting to a windows
  52. related newsgroup, not comp.lang.c.
  53.  
  54. >The problem is Boundschecker consistently reports memory leaks for the
  55. >larger buffer size mallocs contained WITHIN the fgets function...
  56.  
  57. It is rather unlikely that fgets() calls malloc as part of its normal
  58. handling. However the stdio buffering code can allocate a buffer on the first
  59. read or write call after a stream is opened. You can alter this behaviour
  60. using setbuf() or setvbuf() before the first stream read/write.
  61.  
  62. >Any help on resolving this recurrent problem, or just an indication
  63. >that this is perhaps an erroneous error reported by Boundschecker
  64. >would be greatly appreciated.
  65.  
  66. IMHO the most likely explanation is still a bug somewhere else in your
  67. program that has corrupted the heap. I don't know Boundschecker but I bet
  68. it can't detect all bounds violations.
  69.  
  70. -- 
  71. -----------------------------------------
  72. Lawrence Kirby | fred@genesis.demon.co.uk
  73. Wilts, England | 70734.126@compuserve.com
  74. -----------------------------------------
  75.